﻿-- =============================================
-- Author:		Wolf Gilbert
-- Create date: 7/16/06
-- Description:	
-- Modified date:12/14/06
-- Description:	Changed to RuntimeServer
-- =============================================
CREATE PROCEDURE [ServiceEngine].[UpdateRuntimeServer]
	@Name nvarchar(400),	
	@Description ntext = null,
	@CatalogURI ntext = null,
	@CatalogBindingID uniqueidentifier = null,
	@NotificationURI ntext = null,
	@NotificationBindingID uniqueidentifier = null,
	@BrokerURI ntext = null,
	@BrokerBindingID uniqueidentifier = null,
	@ListenerURI ntext = null,
	@ListenerBindingID uniqueidentifier = null,
	@HostName ntext = null,
	@ID uniqueidentifier,
	@PolicyID uniqueidentifier = null,
	@ReceiveNotifications bit = null
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		UPDATE	ServiceEngine.RuntimeServers 
		SET		NotificationURI = @NotificationURI,
				CatalogURI = @CatalogURI,
				BrokerURI = @BrokerURI,
				ListenerURI = @ListenerURI,
				NotificationBindingID = @NotificationBindingID,
				CatalogBindingID = @CatalogBindingID,
				BrokerBindingID = @BrokerBindingID,
				ListenerBindingID = @ListenerBindingID,
				HostName = @HostName,
				PolicyID = @PolicyID,
				ReceiveNotifications = ISNULL(@ReceiveNotifications, ReceiveNotifications)
		WHERE	RuntimeServerID = @ID

		UPDATE	ServiceEngine.Names
		SET		EntityName = @Name,
				EntityDescription = @Description
		WHERE	EntityID = @ID and EntityTypeID = 0

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH

END


